package observer;

import observer.Subject;

// 观察者模式的 Observer
public abstract class Observer {
    protected Subject subject;
    protected String name;
    public abstract void update();

    public Observer() {
    }

    public Observer(Subject subject) {
        this.subject = subject;
        this.subject.attach(this);
    }

    public Subject getSbuject() {
        return subject;
    }

    public void setSbuject(Subject sbuject) {
        this.subject = sbuject;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Observer{" +
                "sbuject=" + subject +
                ", name='" + name + '\'' +
                '}';
    }
}
